<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>InFact: src/infact/example.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">InFact
   
   </div>
   <div id="projectbrief">Interpreter and factory for easily creating C++ objects at run-time</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/infact/example.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="example_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright 2014, Google Inc.</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// Redistribution and use in source and binary forms, with or without</span>
<a name="l00005"></a>00005 <span class="comment">// modification, are permitted provided that the following conditions are</span>
<a name="l00006"></a>00006 <span class="comment">// met:</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">//   * Redistributions of source code must retain the above copyright</span>
<a name="l00009"></a>00009 <span class="comment">//     notice, this list of conditions and the following disclaimer.</span>
<a name="l00010"></a>00010 <span class="comment">//   * Redistributions in binary form must reproduce the above</span>
<a name="l00011"></a>00011 <span class="comment">//     copyright notice, this list of conditions and the following disclaimer</span>
<a name="l00012"></a>00012 <span class="comment">//     in the documentation and/or other materials provided with the</span>
<a name="l00013"></a>00013 <span class="comment">//     distribution.</span>
<a name="l00014"></a>00014 <span class="comment">//   * Neither the name of Google Inc. nor the names of its</span>
<a name="l00015"></a>00015 <span class="comment">//     contributors may be used to endorse or promote products derived from</span>
<a name="l00016"></a>00016 <span class="comment">//     this software without specific prior written permission.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<a name="l00019"></a>00019 <span class="comment">// &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<a name="l00020"></a>00020 <span class="comment">// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<a name="l00021"></a>00021 <span class="comment">// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
<a name="l00022"></a>00022 <span class="comment">// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00023"></a>00023 <span class="comment">// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
<a name="l00024"></a>00024 <span class="comment">// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
<a name="l00025"></a>00025 <span class="comment">// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
<a name="l00026"></a>00026 <span class="comment">// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00027"></a>00027 <span class="comment">// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
<a name="l00028"></a>00028 <span class="comment">// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00029"></a>00029 <span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00030"></a>00030 <span class="comment">//</span>
<a name="l00031"></a>00031 <span class="comment">//</span>
<a name="l00039"></a>00039 <span class="comment"></span>
<a name="l00040"></a>00040 <span class="preprocessor">#ifndef INFACT_EXAMPLE_H_</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define INFACT_EXAMPLE_H_</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;<a class="code" href="factory_8h.html" title="Provides a generic dynamic object factory.">factory.h</a>&quot;</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="keyword">namespace </span>infact {
<a name="l00048"></a>00048 
<a name="l00050"></a><a class="code" href="classinfact_1_1_date.html">00050</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_date.html" title="An interface to represent a date.">Date</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_factory_constructible.html" title="An interface simply to make it easier to implement Factory-constructible types by implementing both r...">FactoryConstructible</a> {
<a name="l00051"></a>00051  <span class="keyword">public</span>:
<a name="l00053"></a><a class="code" href="classinfact_1_1_date.html#a51d58e539330606fefcf1d59ca4c92ea">00053</a>   <a class="code" href="classinfact_1_1_date.html#a51d58e539330606fefcf1d59ca4c92ea" title="Constructs this date.">Date</a>() {}
<a name="l00055"></a><a class="code" href="classinfact_1_1_date.html#a63969a17e80e056d25fdaaf961d7d158">00055</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_date.html#a63969a17e80e056d25fdaaf961d7d158" title="Destroys this date.">~Date</a>() {}
<a name="l00056"></a>00056 
<a name="l00058"></a>00058   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date.html#a8074d68415b81e660f4149ca4c7b0895" title="Returns the year.">year</a>() <span class="keyword">const</span> = 0;
<a name="l00060"></a>00060   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date.html#ab82b23c8104b02af37e590aef38e7655" title="Returns the month.">month</a>() <span class="keyword">const</span> = 0;
<a name="l00062"></a>00062   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date.html#a2927247ca4955ff4bf9706f7687327e1" title="Returns the day.">day</a>() <span class="keyword">const</span> = 0;
<a name="l00063"></a>00063 };
<a name="l00064"></a>00064 
<a name="l00068"></a><a class="code" href="example_8h.html#a9ffdcb7be895354ae6e0b0724b4c40bd">00068</a> <span class="preprocessor">#define REGISTER_DATE(TYPE) \</span>
<a name="l00069"></a>00069 <span class="preprocessor">  REGISTER_NAMED(TYPE,TYPE,Date)</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span>
<a name="l00075"></a><a class="code" href="classinfact_1_1_date_impl.html">00075</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_date_impl.html" title="An implementation of the Date interface that can be constructed by a Factory (because of the REGISTER...">DateImpl</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_date.html" title="An interface to represent a date.">Date</a> {
<a name="l00076"></a>00076  <span class="keyword">public</span>:
<a name="l00078"></a><a class="code" href="classinfact_1_1_date_impl.html#a09cd6f78d193d97ec2dfffe97d218d30">00078</a>   <a class="code" href="classinfact_1_1_date_impl.html#a09cd6f78d193d97ec2dfffe97d218d30" title="Constructs this instance.">DateImpl</a>() : <a class="code" href="classinfact_1_1_date.html" title="An interface to represent a date.">Date</a>() {}
<a name="l00080"></a><a class="code" href="classinfact_1_1_date_impl.html#a520cc74384c72498f5f0732edce4b35e">00080</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_date_impl.html#a520cc74384c72498f5f0732edce4b35e" title="Destroys this instance.">~DateImpl</a>() {}
<a name="l00081"></a>00081 
<a name="l00083"></a><a class="code" href="classinfact_1_1_date_impl.html#ae20654d42981513aa0bf03d89e103457">00083</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_date_impl.html#ae20654d42981513aa0bf03d89e103457" title="Registers three required initializers.">RegisterInitializers</a>(<a class="code" href="classinfact_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers) {
<a name="l00084"></a>00084     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_date_impl.html#ac674abd023bb96b6930d1c94dec66a7d">year</a>);
<a name="l00085"></a>00085     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_date_impl.html#af2fc3157cb4d05dc96870b93bb6d1037">month</a>);
<a name="l00086"></a>00086     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_date_impl.html#ad80baba5993e72543cfa0eb03b4e6aec">day</a>);
<a name="l00087"></a>00087   }
<a name="l00088"></a>00088 
<a name="l00090"></a><a class="code" href="classinfact_1_1_date_impl.html#ac674abd023bb96b6930d1c94dec66a7d">00090</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date_impl.html#ac674abd023bb96b6930d1c94dec66a7d">year</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> year_; }
<a name="l00092"></a><a class="code" href="classinfact_1_1_date_impl.html#af2fc3157cb4d05dc96870b93bb6d1037">00092</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date_impl.html#af2fc3157cb4d05dc96870b93bb6d1037">month</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> month_; }
<a name="l00094"></a><a class="code" href="classinfact_1_1_date_impl.html#ad80baba5993e72543cfa0eb03b4e6aec">00094</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_date_impl.html#ad80baba5993e72543cfa0eb03b4e6aec">day</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> day_; }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096  <span class="keyword">private</span>:
<a name="l00097"></a>00097   <span class="keywordtype">int</span> year_;
<a name="l00098"></a>00098   <span class="keywordtype">int</span> month_;
<a name="l00099"></a>00099   <span class="keywordtype">int</span> day_;
<a name="l00100"></a>00100 };
<a name="l00101"></a>00101 
<a name="l00103"></a><a class="code" href="classinfact_1_1_person.html">00103</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_person.html" title="An interface representing a person.">Person</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_factory_constructible.html" title="An interface simply to make it easier to implement Factory-constructible types by implementing both r...">FactoryConstructible</a> {
<a name="l00104"></a>00104  <span class="keyword">public</span>:
<a name="l00106"></a><a class="code" href="classinfact_1_1_person.html#a5397db53a6352ebd6c27327299d54b43">00106</a>   <a class="code" href="classinfact_1_1_person.html#a5397db53a6352ebd6c27327299d54b43" title="Constructs this abstract person.">Person</a>() {}
<a name="l00108"></a><a class="code" href="classinfact_1_1_person.html#aea7b725674f0ac58c2233c6b55063fae">00108</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_person.html#aea7b725674f0ac58c2233c6b55063fae" title="Destroys this abstract person.">~Person</a>() {}
<a name="l00109"></a>00109 
<a name="l00111"></a>00111   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classinfact_1_1_person.html#ab29c5ad83306b7ec95e3784269a60243" title="Returns the name of this person.">name</a>() <span class="keyword">const</span> = 0;
<a name="l00113"></a>00113   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_person.html#abceb62cace545c8e3007802ddeca0469" title="Returns the height in centimeters of this person.">cm_height</a>() <span class="keyword">const</span> = 0;
<a name="l00115"></a>00115   <span class="keyword">virtual</span> shared_ptr&lt;const Date&gt; <a class="code" href="classinfact_1_1_person.html#afc17e7f54f0b10420381af0152d4a9e3" title="Returns the birthday of this person.">birthday</a>() <span class="keyword">const</span> = 0;
<a name="l00116"></a>00116 };
<a name="l00117"></a>00117 
<a name="l00122"></a><a class="code" href="example_8h.html#a47cd57efd48ac0ef0c8d4dcac5d4aa5a">00122</a> <span class="preprocessor">#define REGISTER_PERSON(TYPE) \</span>
<a name="l00123"></a>00123 <span class="preprocessor">  REGISTER_NAMED(TYPE,TYPE,Person)</span>
<a name="l00124"></a>00124 <span class="preprocessor"></span>
<a name="l00129"></a><a class="code" href="classinfact_1_1_person_impl.html">00129</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_person_impl.html" title="A concrete implementation of the Person interface that can be constructed by a Factory (because of th...">PersonImpl</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_person.html" title="An interface representing a person.">Person</a> {
<a name="l00130"></a>00130  <span class="keyword">public</span>:
<a name="l00132"></a><a class="code" href="classinfact_1_1_person_impl.html#a93eea8defa90832b2068a1263bb1952b">00132</a>   <a class="code" href="classinfact_1_1_person_impl.html#a93eea8defa90832b2068a1263bb1952b" title="Constructs this person.">PersonImpl</a>() : <a class="code" href="classinfact_1_1_person.html" title="An interface representing a person.">Person</a>() {}
<a name="l00134"></a><a class="code" href="classinfact_1_1_person_impl.html#a9605a9b3c908d72f9734db6df62012e6">00134</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_person_impl.html#a9605a9b3c908d72f9734db6df62012e6" title="Destroys this person.">~PersonImpl</a>() {}
<a name="l00135"></a>00135 
<a name="l00137"></a><a class="code" href="classinfact_1_1_person_impl.html#a289e8cb9cedc6c8c42d0ae743b014e51">00137</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_person_impl.html#a289e8cb9cedc6c8c42d0ae743b014e51" title="Registers one required and two optional initializers.">RegisterInitializers</a>(<a class="code" href="classinfact_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers) {
<a name="l00138"></a>00138     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_person_impl.html#a08751ddf25700e3a7bf3814fa1a7083f">name</a>);
<a name="l00139"></a>00139     <a class="code" href="factory_8h.html#a6398dd334cb48923f39b26dbcf2497b9" title="A macro to make it easy to register a parameter for initialization inside a RegisterInitializers impl...">INFACT_ADD_PARAM_</a>(<a class="code" href="classinfact_1_1_person_impl.html#a0f57e6a613dd050b478948bfa53f2df5">cm_height</a>);
<a name="l00140"></a>00140     <a class="code" href="factory_8h.html#a6398dd334cb48923f39b26dbcf2497b9" title="A macro to make it easy to register a parameter for initialization inside a RegisterInitializers impl...">INFACT_ADD_PARAM_</a>(<a class="code" href="classinfact_1_1_person_impl.html#a655a0442b2efc86f93eaa5dfd24b76be">birthday</a>);
<a name="l00141"></a>00141   }
<a name="l00142"></a>00142 
<a name="l00144"></a><a class="code" href="classinfact_1_1_person_impl.html#a08751ddf25700e3a7bf3814fa1a7083f">00144</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classinfact_1_1_person_impl.html#a08751ddf25700e3a7bf3814fa1a7083f">name</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> name_; }
<a name="l00146"></a><a class="code" href="classinfact_1_1_person_impl.html#a0f57e6a613dd050b478948bfa53f2df5">00146</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_person_impl.html#a0f57e6a613dd050b478948bfa53f2df5">cm_height</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> cm_height_; }
<a name="l00148"></a><a class="code" href="classinfact_1_1_person_impl.html#a655a0442b2efc86f93eaa5dfd24b76be">00148</a>   <span class="keyword">virtual</span> shared_ptr&lt;const Date&gt; <a class="code" href="classinfact_1_1_person_impl.html#a655a0442b2efc86f93eaa5dfd24b76be">birthday</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> birthday_; }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150  <span class="keyword">private</span>:
<a name="l00151"></a>00151   <span class="keywordtype">string</span> name_;
<a name="l00152"></a>00152   <span class="keywordtype">int</span> cm_height_;
<a name="l00153"></a>00153   shared_ptr&lt;Date&gt; birthday_;
<a name="l00154"></a>00154 };
<a name="l00155"></a>00155 
<a name="l00157"></a><a class="code" href="classinfact_1_1_animal.html">00157</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_animal.html" title="A very simple class to represent an animal.">Animal</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_factory_constructible.html" title="An interface simply to make it easier to implement Factory-constructible types by implementing both r...">FactoryConstructible</a> {
<a name="l00158"></a>00158  <span class="keyword">public</span>:
<a name="l00160"></a><a class="code" href="classinfact_1_1_animal.html#ac3ffc1549c7a033ca6e13c2085a6f9da">00160</a>   <a class="code" href="classinfact_1_1_animal.html#ac3ffc1549c7a033ca6e13c2085a6f9da" title="Constructs a generic animal.">Animal</a>() {}
<a name="l00162"></a><a class="code" href="classinfact_1_1_animal.html#a9de1a34ad478b0ccfb03d38363424e19">00162</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_animal.html#a9de1a34ad478b0ccfb03d38363424e19" title="Destroys this animal.">~Animal</a>() {}
<a name="l00163"></a>00163 
<a name="l00165"></a>00165   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classinfact_1_1_animal.html#a4a4d3b54ae6ac6a7cafc1ea0406d0e91" title="Returns the name of this animal.">name</a>() <span class="keyword">const</span> = 0;
<a name="l00166"></a>00166 
<a name="l00168"></a>00168   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_animal.html#a1819fb004f01e261bf4205fb0c8dd8f3" title="Returns the age of this animal.">age</a>() <span class="keyword">const</span> = 0;
<a name="l00169"></a>00169 };
<a name="l00170"></a>00170 
<a name="l00175"></a><a class="code" href="example_8h.html#a8373608da8a006b760cbb66b6205fffe">00175</a> <span class="preprocessor">#define REGISTER_ANIMAL(TYPE) \</span>
<a name="l00176"></a>00176 <span class="preprocessor">  REGISTER_NAMED(TYPE,TYPE,Animal)</span>
<a name="l00177"></a>00177 <span class="preprocessor"></span>
<a name="l00179"></a><a class="code" href="classinfact_1_1_cow.html">00179</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_cow.html" title="A class to represent a cow.">Cow</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_animal.html" title="A very simple class to represent an animal.">Animal</a> {
<a name="l00180"></a>00180 <span class="keyword">public</span>:
<a name="l00182"></a><a class="code" href="classinfact_1_1_cow.html#aed06eeb55e758e22684621260b886fc5">00182</a>   <a class="code" href="classinfact_1_1_cow.html#aed06eeb55e758e22684621260b886fc5" title="Constructs a cow.">Cow</a>() : <a class="code" href="classinfact_1_1_animal.html" title="A very simple class to represent an animal.">Animal</a>() {
<a name="l00183"></a>00183     age_ = 2; <span class="comment">// default age, since age is optional</span>
<a name="l00184"></a>00184   }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   <span class="comment">// Destroys this instance.</span>
<a name="l00187"></a><a class="code" href="classinfact_1_1_cow.html#ad1af3a6bfa73b1a37c869d1666b966ed">00187</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_cow.html#ad1af3a6bfa73b1a37c869d1666b966ed">~Cow</a>() {}
<a name="l00188"></a>00188 
<a name="l00189"></a><a class="code" href="classinfact_1_1_cow.html#a8fbdb40e5f983cd20f2caa15b72a227b">00189</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_cow.html#a8fbdb40e5f983cd20f2caa15b72a227b" title="Registers data members of this class for initialization when an instance is constructed via the Facto...">RegisterInitializers</a>(<a class="code" href="classinfact_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers) {
<a name="l00190"></a>00190     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_cow.html#a7403aa2e0f5e922f4867813bcf6048d5" title="Returns the name of this animal.">name</a>);
<a name="l00191"></a>00191     <a class="code" href="factory_8h.html#a6398dd334cb48923f39b26dbcf2497b9" title="A macro to make it easy to register a parameter for initialization inside a RegisterInitializers impl...">INFACT_ADD_PARAM_</a>(<a class="code" href="classinfact_1_1_cow.html#aa1b7f4a657955eb096bb9c407a8a0b28" title="Returns the age of this animal.">age</a>);
<a name="l00192"></a>00192   }
<a name="l00193"></a>00193 
<a name="l00195"></a><a class="code" href="classinfact_1_1_cow.html#a7403aa2e0f5e922f4867813bcf6048d5">00195</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classinfact_1_1_cow.html#a7403aa2e0f5e922f4867813bcf6048d5" title="Returns the name of this animal.">name</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> name_; }
<a name="l00196"></a><a class="code" href="classinfact_1_1_cow.html#aa1b7f4a657955eb096bb9c407a8a0b28">00196</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_cow.html#aa1b7f4a657955eb096bb9c407a8a0b28" title="Returns the age of this animal.">age</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> age_; }
<a name="l00197"></a>00197 <span class="keyword">private</span>:
<a name="l00198"></a>00198   <span class="keywordtype">string</span> name_;
<a name="l00199"></a>00199   <span class="keywordtype">int</span> age_;
<a name="l00200"></a>00200 };
<a name="l00201"></a>00201 
<a name="l00207"></a><a class="code" href="classinfact_1_1_sheep.html">00207</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_sheep.html" title="A sheep.">Sheep</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_animal.html" title="A very simple class to represent an animal.">Animal</a> {
<a name="l00208"></a>00208  <span class="keyword">public</span>:
<a name="l00210"></a><a class="code" href="classinfact_1_1_sheep.html#a98ac95da1aff69c590b62ecc64fec605">00210</a>   <a class="code" href="classinfact_1_1_sheep.html#a98ac95da1aff69c590b62ecc64fec605" title="Constructs a sheep.">Sheep</a>() : <a class="code" href="classinfact_1_1_animal.html" title="A very simple class to represent an animal.">Animal</a>() {}
<a name="l00212"></a><a class="code" href="classinfact_1_1_sheep.html#a85b9c2d8a9379078d29ec82e3ab4e328">00212</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_sheep.html#a85b9c2d8a9379078d29ec82e3ab4e328" title="Destroys a sheep.">~Sheep</a>() {}
<a name="l00213"></a>00213 
<a name="l00218"></a><a class="code" href="classinfact_1_1_sheep.html#a5fc9522fe9d8cb71ef61ddb732aff63f">00218</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_sheep.html#a5fc9522fe9d8cb71ef61ddb732aff63f" title="Registers one required and two optional inititalizers.">RegisterInitializers</a>(<a class="code" href="classinfact_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers) {
<a name="l00219"></a>00219     <a class="code" href="factory_8h.html#ad079b320f02a7a940b66c2e10162e321" title="Identical to INFACT_ADD_PARAM_ but for a required parameter.">INFACT_ADD_REQUIRED_PARAM_</a>(<a class="code" href="classinfact_1_1_sheep.html#a2fbf359eb99794a182fea7a7b1e00469">name</a>);
<a name="l00220"></a>00220     <a class="code" href="factory_8h.html#a6398dd334cb48923f39b26dbcf2497b9" title="A macro to make it easy to register a parameter for initialization inside a RegisterInitializers impl...">INFACT_ADD_PARAM_</a>(<a class="code" href="classinfact_1_1_sheep.html#a7311016b4dfbc9d6e63628bbbe574e1e" title="Returns the counts of this sheep.">counts</a>);
<a name="l00221"></a>00221     <span class="comment">// We can pass in a nullptr, if we don&#39;t want to directly</span>
<a name="l00222"></a>00222     <span class="comment">// initialize a data member of this class, but instead want to</span>
<a name="l00223"></a>00223     <span class="comment">// simply grab something from the Environment after this method</span>
<a name="l00224"></a>00224     <span class="comment">// has been invoked; see the PostInit method declared below</span>
<a name="l00225"></a>00225     <span class="comment">// (defined in example.cc).</span>
<a name="l00226"></a>00226     <span class="comment">//</span>
<a name="l00227"></a>00227     <span class="comment">// As of v1.0.6, the new INFACT_ADD_TEMPORARY macro makes it very</span>
<a name="l00228"></a>00228     <span class="comment">// easy to add such temporary variables in a very readable way.</span>
<a name="l00229"></a>00229     <a class="code" href="factory_8h.html#ae1e1f80dddb9011fa00e128c3eccc7bd" title="A macro to make it easier to register a temporary variable inside a RegisterInitializers implementati...">INFACT_ADD_TEMPORARY</a>(<span class="keywordtype">int</span>, <a class="code" href="classinfact_1_1_sheep.html#af6c829e8f5889e74769039a377a8f51b">age</a>);
<a name="l00230"></a>00230   }
<a name="l00231"></a>00231 
<a name="l00236"></a>00236   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_sheep.html#a69f798764ffea946753bd06e678407cf" title="Grabs the variable named &quot;age&quot; from the Environment (set up by RegisterInitializers) and sets this sh...">PostInit</a>(<span class="keyword">const</span> <a class="code" href="classinfact_1_1_environment.html" title="An interface for an environment in which variables of various types are mapped to their values...">Environment</a> *env, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;init_str);
<a name="l00237"></a>00237 
<a name="l00239"></a><a class="code" href="classinfact_1_1_sheep.html#a2fbf359eb99794a182fea7a7b1e00469">00239</a>   <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classinfact_1_1_sheep.html#a2fbf359eb99794a182fea7a7b1e00469">name</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> name_; }
<a name="l00241"></a><a class="code" href="classinfact_1_1_sheep.html#af6c829e8f5889e74769039a377a8f51b">00241</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_sheep.html#af6c829e8f5889e74769039a377a8f51b">age</a>()<span class="keyword"> const </span>{
<a name="l00242"></a>00242     <span class="keywordflow">return</span> -1;  <span class="comment">// Always returns -1, because sheep are timeless.</span>
<a name="l00243"></a>00243   }
<a name="l00245"></a><a class="code" href="classinfact_1_1_sheep.html#a7311016b4dfbc9d6e63628bbbe574e1e">00245</a>   <span class="keyword">const</span> vector&lt;int&gt; &amp;<a class="code" href="classinfact_1_1_sheep.html#a7311016b4dfbc9d6e63628bbbe574e1e" title="Returns the counts of this sheep.">counts</a>() { <span class="keywordflow">return</span> counts_; }
<a name="l00246"></a>00246  <span class="keyword">private</span>:
<a name="l00247"></a>00247   <span class="keywordtype">string</span> name_;
<a name="l00248"></a>00248   <span class="keywordtype">int</span> age_;
<a name="l00249"></a>00249   <span class="comment">// The various times people have counted this sheep when falling asleep.</span>
<a name="l00250"></a>00250   vector&lt;int&gt; counts_;
<a name="l00251"></a>00251 };
<a name="l00252"></a>00252 
<a name="l00254"></a><a class="code" href="classinfact_1_1_pet_owner.html">00254</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_pet_owner.html" title="An owner of a pet.">PetOwner</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_factory_constructible.html" title="An interface simply to make it easier to implement Factory-constructible types by implementing both r...">FactoryConstructible</a> {
<a name="l00255"></a>00255  <span class="keyword">public</span>:
<a name="l00257"></a><a class="code" href="classinfact_1_1_pet_owner.html#a8320220c05b1fc762503e02044c4f809">00257</a>   <a class="code" href="classinfact_1_1_pet_owner.html#a8320220c05b1fc762503e02044c4f809" title="Constructs a generic pet owner.">PetOwner</a>() {}
<a name="l00258"></a>00258 
<a name="l00260"></a><a class="code" href="classinfact_1_1_pet_owner.html#ad54df2487e5fa835ac3bc49dc371d011">00260</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_pet_owner.html#ad54df2487e5fa835ac3bc49dc371d011" title="Destroys this pet owner.">~PetOwner</a>() {}
<a name="l00261"></a>00261 
<a name="l00263"></a>00263   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_pet_owner.html#ad69dd29b3deed52c57f02a384761979e" title="Returns the number of pets owned by this pet owner.">GetNumberOfPets</a>() = 0;
<a name="l00264"></a>00264 
<a name="l00266"></a>00266   <span class="keyword">virtual</span> shared_ptr&lt;Animal&gt; <a class="code" href="classinfact_1_1_pet_owner.html#ad02375b2fb31e6463ddec16d02ac39cf" title="Gets the pet with the specified index owned by this pet owner.">GetPet</a>(<span class="keywordtype">int</span> i) = 0;
<a name="l00267"></a>00267 };
<a name="l00268"></a>00268 
<a name="l00273"></a><a class="code" href="example_8h.html#a9533639d16f8b0269c286444897ff13d">00273</a> <span class="preprocessor">#define REGISTER_PET_OWNER(TYPE) \</span>
<a name="l00274"></a>00274 <span class="preprocessor">  REGISTER_NAMED(TYPE,TYPE,PetOwner)</span>
<a name="l00275"></a>00275 <span class="preprocessor"></span>
<a name="l00278"></a><a class="code" href="classinfact_1_1_human_pet_owner.html">00278</a> <span class="keyword">class </span><a class="code" href="classinfact_1_1_human_pet_owner.html" title="A concrete type of PetOwner that can be constructed by a Factory&lt;PetOwner&gt; instance.">HumanPetOwner</a> : <span class="keyword">public</span> <a class="code" href="classinfact_1_1_pet_owner.html" title="An owner of a pet.">PetOwner</a> {
<a name="l00279"></a>00279  <span class="keyword">public</span>:
<a name="l00281"></a><a class="code" href="classinfact_1_1_human_pet_owner.html#a9d1585c751db120234f4bce60d8b81ae">00281</a>   <a class="code" href="classinfact_1_1_human_pet_owner.html#a9d1585c751db120234f4bce60d8b81ae" title="Constructs a human pet owner.">HumanPetOwner</a>() : <a class="code" href="classinfact_1_1_pet_owner.html" title="An owner of a pet.">PetOwner</a>() {}
<a name="l00282"></a>00282 
<a name="l00284"></a><a class="code" href="classinfact_1_1_human_pet_owner.html#a6e16f80e770683d67533a18e765d9970">00284</a>   <span class="keyword">virtual</span> <a class="code" href="classinfact_1_1_human_pet_owner.html#a6e16f80e770683d67533a18e765d9970" title="Destroys a human pet owner.">~HumanPetOwner</a>() {}
<a name="l00285"></a>00285 
<a name="l00287"></a><a class="code" href="classinfact_1_1_human_pet_owner.html#a60908d8d6c4b89d353c8a487992ea76b">00287</a>   <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classinfact_1_1_human_pet_owner.html#a60908d8d6c4b89d353c8a487992ea76b" title="Registers a single required initializer.">RegisterInitializers</a>(<a class="code" href="classinfact_1_1_initializers.html" title="A container for all the member initializers for a particular Factory-constructible instance...">Initializers</a> &amp;initializers) {
<a name="l00288"></a>00288     initializers.<a class="code" href="classinfact_1_1_initializers.html#a33d96794d73289dd072351a8fa269728" title="This method is the raison d&#39;etre of this class: a method to make it easy to add all supported types o...">Add</a>(<span class="stringliteral">&quot;pets&quot;</span>, &amp;pets_, <span class="keyword">true</span>);
<a name="l00289"></a>00289   }
<a name="l00290"></a>00290 
<a name="l00292"></a><a class="code" href="classinfact_1_1_human_pet_owner.html#ac50757937a9715f9151b4a46d3db7373">00292</a>   <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="classinfact_1_1_human_pet_owner.html#ac50757937a9715f9151b4a46d3db7373" title="Returns the number of pets owned by this pet owner.">GetNumberOfPets</a>() {
<a name="l00293"></a>00293     <span class="keywordflow">return</span> pets_.size();
<a name="l00294"></a>00294   }
<a name="l00295"></a>00295 
<a name="l00297"></a><a class="code" href="classinfact_1_1_human_pet_owner.html#a9c680a005a4d0746dd3cbaca95b75068">00297</a>   <span class="keyword">virtual</span> shared_ptr&lt;Animal&gt; <a class="code" href="classinfact_1_1_human_pet_owner.html#a9c680a005a4d0746dd3cbaca95b75068" title="Gets the pet with the specified index owned by this pet owner.">GetPet</a>(<span class="keywordtype">int</span> i) {
<a name="l00298"></a>00298     <span class="keywordflow">return</span> pets_.at(i);
<a name="l00299"></a>00299   }
<a name="l00300"></a>00300 
<a name="l00301"></a>00301  <span class="keyword">private</span>:
<a name="l00302"></a>00302   vector&lt;shared_ptr&lt;Animal&gt; &gt; pets_;
<a name="l00303"></a>00303 };
<a name="l00304"></a>00304 
<a name="l00305"></a>00305 }  <span class="comment">// namespace infact</span>
<a name="l00306"></a>00306 
<a name="l00307"></a>00307 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Wed Apr 23 2014 10:07:52 for InFact by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
